package custom;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Performances {
	
	private int quizId, userId, score;
	
	public Performances(int quizId, int userId, int score){
		this.quizId = quizId;
		this.userId = userId;
		this.score = score;
	}
	
	public String getHtml(){
		return "";
	}

	public static Performances [] last5byUzer(int quizId, int userId) throws SQLException{
		ResultSet rs = QuizDBC.getInstance().selectFromQuizescores(userId, quizId, 5, 1);
		Performances [] per = new Performances[5];
		int i = 0;
		while(rs.next()){
			Performances p = new Performances(quizId, userId, rs.getInt("score"));
			per[0] = p;
			i++;
		}
		return per;
	}


	public static Performances [] last5inQuiz(int quizId) throws SQLException{
		ResultSet rs = QuizDBC.getInstance().selectFromQuizescores(-1, quizId, 5, 1);
		Performances [] per = new Performances[5];
		int i = 0;
		while(rs.next()){
			Performances p = new Performances(quizId, rs.getInt("userid"), rs.getInt("score"));
			per[0] = p;
			i++;
		}
		return per;
	}

	public static Performances [] top5ever(int quizId) throws SQLException{
		ResultSet rs = QuizDBC.getInstance().selectFromQuizescores(-1, quizId, 5, 0);
		Performances [] per = new Performances[5];
		int i = 0;
		while(rs.next()){
			Performances p = new Performances(quizId, rs.getInt("userid"), rs.getInt("score"));
			per[0] = p;
			i++;
		}
		return per;
	}
	
	//amis bazidan amogeba ar gviweria!!!
	public static Performances [] top5today(int quizId){
		return null;
	}
	
	
	public void savePerformance(int quizeId, int userId, int score){
		QuizDBC.getInstance().insertQuizScores(quizeId, userId, score);
	}
}
